package com.houdoudou.com.owner;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;


public class OwnerServlet extends HttpServlet {
	private static final long serialVersionUID = 2L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		   req.setCharacterEncoding("UTF-8"); 
		    resp.setCharacterEncoding("UTF-8");
		    PrintWriter print=resp.getWriter();  
		       
	        String jsonData=req.getParameter("jsonData");
	        String PostCode=req.getParameter("PostCode");
	        
	        int postCode=Integer.parseInt(PostCode);
	        System.out.println("there is requst in OwnerServlet"+PostCode+jsonData);
	        switch(postCode){
	        case 1:  {  //1验证管理员是否注册，成功 返回e参数，失败返回失败原因
	        	      JSONObject temp=  OwnerManagement.loginCheck(jsonData);
	    	          print.println( temp.toString()); 
	    	          System.out.println("data back to app----"+temp);
	    	          break;} 
	       
			case 2:  {  //1业主管理机器，
      	      JSONObject temp=  OwnerDoSth.manageMachine(jsonData);
  	          print.println( temp.toString()); 
  	          System.out.println("data back to app----"+temp);
  	          break;} 
			case 3:  {  //1业主查询自己或者修改密码这里，
	      	      JSONObject temp=    OwnerDoSth.manageSelf(jsonData);
	  	          print.println( temp.toString()); 
	  	          System.out.println("data back to app----"+temp);
	  	          break;} 
			case 4:  {  //业主管理供应商
	      	      JSONObject temp=    OwnerDoSth.manageSupplier(jsonData);
	  	          print.println( temp.toString()); 
	  	          System.out.println("data back to app----"+temp);
	  	          break;} 
			case 5:  {  //业主分配自提柜
	      	      JSONObject temp=    OwnerDoSth.manageDistribute(jsonData);
	  	          print.println( temp.toString()); 
	  	          System.out.println("data back to app----"+temp);
	  	          break;} 
			
     
	        }
	        
	        print.close();  
	 }
	
}
